package com.zy.hh.controller;

import com.zy.hh.pojo.User;
import com.zy.hh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/login.html")
    public String login() {
        return "login";
    }

    @PostMapping("/dologin")
    public String dologin(String username, String password, HttpSession session) {
        User user = userService.login(username, password);
        if (user == null) {
            System.out.println("用户名或者密码输入错误");
            return "redirect:/login.html";
        } else {
            System.out.println("登录成功---");
            session.setAttribute("user", user);
            return "success";
        }
    }
}
